package com.currency.util;

import cn.hutool.core.util.IdUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;

import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class MessageUtil {


    public static void main(String[] args) throws Exception {
        String url = "http://112.91.147.38:8803/sms/v2/std/single_send";

        Map<String, Object> paraMap = new HashMap<>();
        paraMap.put("userid", "J95160");
        SimpleDateFormat sdf = new SimpleDateFormat("MMDDHHMMSS");
        Date d = new Date();

        String dateStr = sdf.format(d);
        String pwd = "J95160" + "00000000" + "100777" + dateStr;
        System.out.println(pwd);
        String sig = DigestUtils.md5Hex(pwd);
        System.out.println(sig);
        paraMap.put("pwd", sig);

        paraMap.put("mobile", "15367319212");


        String contOrg = "欢迎注册伟易通，您的验证码为：778899，请勿告诉他人哦";
        String keyWord = URLEncoder.encode(contOrg, "GBK");
        System.out.println(keyWord);


        System.out.println(paraMap.get("keyWord"));

        paraMap.put("content", keyWord);

        paraMap.put("timestamp", dateStr);
        paraMap.put("custid", "reg" + IdUtil.createSnowflake(1, 1).nextIdStr());

        System.out.println(paraMap.get("custid"));

        String ans = HttpRequest.post(url)
                .header(Header.CONTENT_TYPE, "application/json").header(Header.CONTENT_ENCODING, "GBK").body(JSONObject.toJSONString(paraMap))
                .execute().body();

        System.out.println(ans);
    }



}
